package com.mocha.activities;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

import com.mocha.DB.DBItemBase;
import com.mocha.DB.DBItemFactory;
import com.mocha.DB.DBManager;

public class AccountBookAddActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_account_book_add);
		
		findViewById(R.id.button1).setOnClickListener(btnListener);
		findViewById(R.id.button2).setOnClickListener(btnListener);
		findViewById(R.id.button3).setOnClickListener(btnListener);
		findViewById(R.id.button4).setOnClickListener(btnListener);
	}
	
	OnClickListener btnListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch(v.getId()){
				case R.id.button1: {
					DBItemBase item = DBItemFactory.createDBItem(DBItemFactory.ItemType.AccountBookType);
					item.createTestData();
					DBManager.getInstance(v.getContext()).insertBasicItem(item);
				} break;
				case R.id.button2: {
					DBItemBase[][] dbItems = DBManager.getInstance(v.getContext()).getItems(0, 24000000);
					for(DBItemBase[] items : dbItems) {
						for(DBItemBase item : items) {
							Log.i("DB2", String.format("ID is %d / Type is %d", item.id, item.getType().getValue()));
						}
					}
				} break;
				case R.id.button3: {
					DBItemBase item = DBItemFactory.createDBItem(DBItemFactory.ItemType.DiaryType);
					item.createTestData();
					DBManager.getInstance(v.getContext()).insertBasicItem(item);
				} break;
				case R.id.button4:  {
					DBItemBase item = DBItemFactory.createDBItem(DBItemFactory.ItemType.TodoType);
					item.createTestData();
					DBManager.getInstance(v.getContext()).insertBasicItem(item);
				} break;
			}			
		}
	};

}
